
const http = require('http')
// 创建服务器
const fs= require('fs')
const server = http.createServer(function(req, res) {
    // request是用来接收所有请求信息的对象
    // response用来给客户端做出响应的对象
    // 调用response对象的end方法，可以给客户端做出响应
    let uri =req.url
    console.log(uri);
    if(uri === '/'){
        let data = fs.readFileSync('./list.html')
        res.end(data)
    }
    else if(uri === '/dl.html'){
        let data = fs.readFileSync('./dl.html')
        res.end(data)
    }
    else if(uri === '/dl.css'){
        let data = fs.readFileSync('./dl.css')
        res.end(data)
    }
    else if(uri === '/zc.html'){
        let data = fs.readFileSync('./zc.html')
        res.end(data)
    }
    else if(uri === '/zc.css'){
        let data = fs.readFileSync('./zc.css')
        res.end(data)
    }
    else if(uri === '/gwc.html'){
        let data = fs.readFileSync('./gwc.html')
        res.end(data)
    }
    else if(uri === '/gwc.css'){
        let data = fs.readFileSync('./gwc.css')
        res.end(data)
    }
    else if(uri === '/js/utils.js'){
        let data = fs.readFileSync('./js/utils.js')
        res.end(data)
    }
    else if(uri === '/js/jquery.min.js'){
        let data = fs.readFileSync('./js/jquery.min.js')
        res.end(data)
    }
    else if(uri === '/js/jquery.js'){
        let data = fs.readFileSync('./js/jquery.js')
        res.end(data)
    }
    else if(uri === '/list.html'){
        let data = fs.readFileSync('./list.html')
        res.end(data)
    }
    else if(uri === '/list.css'){
        let data = fs.readFileSync('./list.css')
        res.end(data)
    }
    else if(uri === '/lb.html'){
        let data = fs.readFileSync('./lb.html')
        res.end(data)
    }
    else if(uri === '/lb.css'){
        let data = fs.readFileSync('./lb.css')
        res.end(data)
    }
    else if(uri.includes('/xqy.html')){
        let data = fs.readFileSync('./xqy.html')
        res.end(data)
    }
    else if(uri.includes('/xqy.css')){
        let data = fs.readFileSync('./xqy.css')
        res.end(data)
    }
    else if(uri === '/xg.html'){
        let data = fs.readFileSync('./xg.html')
        res.end(data)
    }
    else if(uri === '/xg.css'){
        let data = fs.readFileSync('./xg.css')
        res.end(data)
    }
    else if(uri === '/font/iconfont.css'){
        let data = fs.readFileSync('./font/iconfont.css')
        res.end(data)
    }
    else if(uri.startsWith('/img')){
        let data = fs.readFileSync('.'+uri)
        res.end(data)
    }
    else if(uri.includes('?')){
        let index = uri.indexOf('?')
        uri = uri.slice(0, index)
        console.log(111, uri);
        let data = fs.readFileSync('.' +uri)
        res.end(data)
    }
    res.end()
})
// 监听端口号
server.listen(12345)